<template> 
<div class="app-container">
    <div class="ces-main">
   
     <v-GetToolBar align="right" :MenuCode="MenuCode"  
        :IsfunEdit='IsfunEdit'
        :Isfunfail='Isfunfail'
        @handeAdd='handeAdd'
        @handeimport='handleUploadOpen'
        @handleEdit='handleEdit'
        @OpenFindForm='OpenFindForm'
        @handlexportData='handlexportData'
        @IsfunEdit='handleIsfunEdit'
        @IsfunDelete='handleIsfunfail'
         :UploadArr = 'UploadArr'
        >

        </v-GetToolBar>

 <el-form
        :inline="true"
        :model="Search"
        class="demo-form-inline"
        size="mini"
      >
      </el-form>
  

        <ces-table 
        size='mini'
        :isSelection='false'
        :isIndex='true'
        :isSearch='true'
        :isHandle='false'
        :StepSN = '0'
        :IsfunEdit='IsfunEdit'
         :Isfunfail='Isfunfail'
        :tableData='tableData' 
        :tableCols='tableCols' 
        :Search='Search'
        @refresh="refresh"
        @handleEdit='handleEdit'
        @handleDelete='delData'
        >
        </ces-table>
        </div>

 <!--搜索弹框-->
    <el-dialog
      title="搜索"
      :visible.sync="SearchDialog"
      custom-class="dialogClass"
      class="searchDialog"
      center
      ref="searchDialog"
      :modal="false"
      :close-on-click-modal="false"
    >
      <el-form :model="Search" label-width="90px" ref="searchForm">
       
       <Search-Form 
        ref="form"   :frame="true"
        size='mini'
        labelWidth = '50px' 
        :searchData = 'Search'
      
         :tableCols = 'tableCols'
        :searchHandle="searchHandle"></Search-Form >
      </el-form>
      <div
        slot="footer"
        :style="{ 'margin-buttom': 0 == 0 ? DialogBtnMargin : DialogBtnMargin }"
      >
        <el-button @click="reform()">重置</el-button>
        <el-button type="primary" @click="refresh()">确 定</el-button>
      </div>
    </el-dialog>



    <el-dialog
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      width="800px"
      top="20px"
       
    >
<el-form :model="name" label-width="80px"  label-position="right">
   <el-tabs type="border-card">
        <el-tab-pane label="IQC检查资料配置">
      <el-form :model="FormData" label-width="90px" ref="MianForm">
       <Mian-Form 
        ref="form"
        :StepSN = '0'
        labelWidth = '100px' 
        :FormData = 'FormData'
         :tableCols = 'tableCols'
        :searchHandle="searchHandle"></Mian-Form >
      </el-form>
        </el-tab-pane>
<div style="float:right ">

 <el-button type="primary" @click="handleOpenClose()">关闭</el-button>
        <el-button type="primary" @click="handleSave()">保存</el-button>

</div>
       
  </el-tabs>
      
</el-form>
     
    </el-dialog>


</div>
</template>

<script>


//引入组件

import cesTable from "../Common/table.vue";
import SearchForm from "../Common/Search.vue";
import MianForm from "../Common/form.vue";

import { funDownload,GetTableColsData } from "@/api/Common";
import { getDataList,UpdateForm,DeletForm,ImportUpdate} from '@/api/MesQMS/QMS_IQCcheckup';
import vGetToolBar from "../Common/GetToolBar";

export default {
  name:"QMSIQCcheckup",
    data(){
         //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看
      
        return {
        MenuCode: "A050901",
        tableData:[],//表格数据
        FormData:[],//表格数据
        tableCols:[ ],//表格列数据
        searchHandle:[],
        StepSN:"0",
        IsfunEdit:false,
          Isfunfail:false,
        Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "001", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件
       
      },
       cities: [
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ], UploadArr: [
        { Fieldname: "ID", CName: "ID" },
        { Fieldname: "TermType", CName: "检验类别" },
        { Fieldname: "Term", CName: "检查项目" },
         { Fieldname: "SorNo", CName: "序号" },
       { Fieldname: "ProductModel", CName: "物料编码" },
        { Fieldname: "testmeThod", CName: "测试方法" },
        { Fieldname: "Tool", CName: "所要工具" },
        { Fieldname: "Range", CName: "测试范围" },
        { Fieldname: "InstrumentPrecision", CName: "仪器精准" },
        { Fieldname: "IsRequiredSpec", CName: "要求规格" },
        { Fieldname: "MAJ", CName: "最大设定值" },
        { Fieldname: "MIN", CName: "最小设定值" },
        { Fieldname: "JudgmentGrade", CName: "质量缺陷" },
        { Fieldname: "SamplQty", CName: "抽检数量" },
        { Fieldname: "DrawingNo", CName: "图纸编号" },
    
        
      ],
       SearchDialog: false,
         DialogBtnMargin: 0,
         dialogVisible: false,
          
        }
    },

   components:{ //引入组件后注册组件
    cesTable, 
     vGetToolBar,
     SearchForm,
     MianForm
   
   },
   mounted(){
    this.getTableCols()
    this.getDataList()
   },
    methods:{
         //搜索重置
    refresh() {
      this.getDataList();
    },
     reform() {
       this.Search = {
        // 查询条件
        // total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "001", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件
      };
       this.getDataList();
    },
      //读取列配置
        async getTableCols(){
        this.tableCols = []
        const res = await  GetTableColsData({InterID:"1555"});
        this.tableCols=res.data;
                  
         },
        async getDataList() {
        const res = await getDataList({ data: JSON.stringify(this.Search) });
        this.tableData = res.data.Table;
        //将data 中的数据放到DataList中
        this.Search.total = res.data.Table1[0].RecordCount;
    
    },OpenFindForm() {
      //打开搜索框
      this.SearchDialog = true;
      //计算外边距
      console.log(this.$refs.searchDialog.offsetHeight);
      this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
    },
    handleOpenClose()
    {
        this.dialogVisible = false
    }, handlexportData() {
      funDownload("1555", JSON.stringify(this.Search));
    }, handleIsfunEdit() {
      this.IsfunEdit=true;
    }, handleIsfunfail() {
       this.Isfunfail=true;
    },async handeAdd() {
      // 新建
    const result = await UpdateForm({ IsPostBack:false,billID:''});
     this.FormData=result.data1.Table[0];
     this.dialogType = 'edit'
        this.dialogVisible = true
        this.checkStrictly = true
      
        this.$nextTick(() => {
          const routes = this.generateRoutes(this.EditObj.routes)
          this.$refs.tree.setCheckedNodes(this.generateArr(routes))
          // set checked state of a node not affects its father and child nodes
          this.checkStrictly = false

        })
        this.getDataList();
    },
   async handleEdit(scope) {
      // 修改

      
    const result = await UpdateForm({ IsPostBack:false,billID:scope.row.ID});
     this.FormData=result.data1.Table[0];
        this.dialogType = 'edit'
        this.dialogVisible = true
        this.checkStrictly = true
      
        this.$nextTick(() => {
          const routes = this.generateRoutes(this.EditObj.routes)
          this.$refs.tree.setCheckedNodes(this.generateArr(routes))
          // set checked state of a node not affects its father and child nodes
          this.checkStrictly = false

        })
        this.getDataList();
      
    },
     async handleSave(scope) {
      // 修改
       this.dialogVisible = false;
    const result = await UpdateForm({ IsPostBack:true,billID:this.FormData.ID, HeadDate: JSON.stringify(this.FormData)});
     this.FormData=result.data1.Table[0];
       
        if (result.code === 20000) {
         
       
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
          this.getDataList();
        } else {
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "error",
          });
        }
      
       
        this.getDataList();
      
    },delData({ $index, row }) {
       this.$confirm('删除操作, 是否继续?', '提示', {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(async () => {
         

         this.tableData.splice($index, 1);

            const result = await DeletForm({
              billID: row.ID,
              IsPostBack: false,
            });

            this.$message({
              type: "success",
              message: result.msg,
            });
          
        })
        .catch((err) => {
          console.error(err);
        });
    },async handleUploadOpen(ploadDate)
    {

debugger
 const result = await ImportUpdate({
           BodyDate: JSON.stringify(ploadDate),
        });

    
            this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
      
    },
      
       
  }
}
</script>

<style lang="scss" scoped>

.app-container {
  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}
.searchDialog ::v-deep .el-dialog__header {
  background: #409eff;
}
.searchDialog ::v-deep .el-dialog__title {
  color: #fff;
}
.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
</style>